﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Collections;

namespace GlassStore.Controllers
{
    [Authorize(Roles = "Administrator")]
    public class UserManagerController : Controller
    {
        //
        // GET: /User/

        public ActionResult Index()
        {
            var users = Membership.GetAllUsers();
            return View(users as IEnumerable);
        }


        //
        // GET: /UserManager/Delete?username=aaa

        public ActionResult Delete(string username)
        {
            var user = Membership.GetUser(username);
            return View(user);
        }

        //
        // POST: /UserManager/Delete?username=aaa

        [HttpPost]
        public ActionResult Delete(string username, FormCollection collection)
        {
            try
            {
                if (!(username.ToLower() == "admin"))
                {
                    Membership.DeleteUser(username, true);
                }

                return RedirectToAction("Index");
            }
            catch
            {
              return RedirectToAction("Index");
            }
        }
    }
}
